package bairui.international.console.web.controller.barter.category;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.servlet.ModelAndView;

import com.lianjing.sh.project.config.web.Project_Config_Web_PageTemplate;
import com.lianjing.sh.spring.web.controller.base.action.Action;
import com.lianjing.sh.spring.web.controller.enhance.module.context.ModuleContext;
import com.lianjing.sh.spring.web.controller.enhance.navigations.context.NavigationContext;

import bairui.international.console.web.controller.barter.category.product.C_Barter_Category_ProductAdd_AddAccess;
import bairui.international.console.web.controller.barter.category.product.C_Barter_Category_ProductDelete_Delete;
import bairui.international.console.web.controller.barter.category.product.C_Barter_Category_ProductDown_Submit;
import bairui.international.console.web.controller.barter.category.product.C_Barter_Category_ProductEdit_EditAccess;
import bairui.international.console.web.controller.barter.category.product.C_Barter_Category_ProductExport_ExcelExport;
import bairui.international.console.web.controller.barter.category.product.C_Barter_Category_ProductImport_ExcelImport;
import bairui.international.console.web.controller.barter.category.product.C_Barter_Category_ProductPublish_Submit;
import bairui.international.console.web.controller.barter.category.product.C_Barter_Category_ProductUp_Submit;
import bairui.international.console.web.controller.barter.category.properties.C_Barter_Category_PropertiesDetail_PageAccess;
import bairui.international.model.domain.jpa.TB_ProductCategory;
import bairui.international.model.domain.jpa.TB_ProductCategoryProperty;
import bairui.international.model.domain.jpa.TB_ProductProperty;
import bairui.international.service.Service_ProductCategory;
import bairui.international.service.Service_ProductCategoryProperty;

/**
 *
 * 详情
 *
 * @generated
 * 
 * @see STest_C_Barter_Category_Detail_DetailAccess 测试
 *
 */
@Controller
public class C_Barter_Category_Detail_DetailAccess
 extends SC_Barter_Category_Detail_DetailAccess 
{
	
	@Autowired private Service_ProductCategory service_ProductCategory;
	@Autowired private Service_ProductCategoryProperty service_ProductCategoryProperty;
	
	/**
	 * 访问详情页面	
	 */
	@SuppressWarnings("serial")
	@Action(DetailAccess.class)
	@GetMapping(DetailAccess.RequestMappingValue)
	public ModelAndView detailAccess(
		ModelMap map, HttpServletRequest request,
		NavigationContext navigationContext, ModuleContext moduleContext, 
		@PathVariable(name=DetailAccess.PathVariableName.Id) long id
	) throws Exception {
		TB_ProductCategory bean = service_ProductCategory.findById(id);
		/* 模块 */
		moduleContext
			.addModule(module_Info.module(
					new Module_Info_OutputModel(bean){
						@Override protected void assign_before() {
							
						}
						@Override protected ArrayList<?> assignProductPropertyToString() {
							List<TB_ProductCategoryProperty> ps = service_ProductCategoryProperty.list(it->it.productCategory.eq(bean));
							return (ArrayList<?>) ps.stream().map(it->{
								TB_ProductProperty p = new TB_ProductProperty();
									p.setName(it.getProductProperty().getName());
								return p;
							})
							.collect(Collectors.toList());
						}
					},
					new C_Barter_Category_PropertiesDetail_PageAccess.PageAccess.Operate(){
						@Override public Object getCategoryId() {
							return bean.getId();
						}
						@Override public boolean displaied() {
							return bean.getParent() == null;
						};
					}
				))
			.addModule(this.module_ProductPage.module(
					new C_Barter_Category_Detail_ProductPage.ProductPage.Operate(){
						@Override public Object getId() {
							return id;
						}
					}, 
					new C_Barter_Category_ProductAdd_AddAccess.AddAccess.Operate(){
						@Override public Object getCategoryId() {
							return id;
						}
					},  
					new C_Barter_Category_ProductImport_ExcelImport.ExcelImport.Operate(){
						@Override public Object getCategoryId() {
							return id;
						}
					},
					new C_Barter_Category_ProductExport_ExcelExport.ExcelExport.Operate(){
						@Override public Object getCategoryId() {
							return id;
						}
					},  
					new C_Barter_Category_ProductEdit_EditAccess.EditAccess.Operate(){
						@Override public Object getId() {
							return "{{:id}}";
						}
						@Override public Object getCategoryId() {
							return id;
						}
					}, 
					new C_Barter_Category_ProductDelete_Delete.Delete.Operate(){
						@Override public Object getId() {
							return "{{:id}}";
						}
						@Override public Object getCategoryId() {
							return id;
						}
					},  
					new C_Barter_Category_ProductPublish_Submit.Submit.Operate(){
						@Override public Object getId() {
							return "{{:id}}";
						}
						@Override public Object getCategoryId() {
							return id;
						}
					}, 
					new C_Barter_Category_ProductUp_Submit.Submit.Operate(){
						@Override public Object getId() {
							return "{{:id}}";
						}
						@Override public Object getCategoryId() {
							return id;
						}
					}, 
					new C_Barter_Category_ProductDown_Submit.Submit.Operate(){
						@Override public Object getId() {
							return "{{:id}}";
						}
						@Override public Object getCategoryId() {
							return id;
						}
					}
				));
		//
		return Project_Config_Web_PageTemplate.Admin_Common(request);
	}
	

}
